package Fundamental.memory;

/**
 * @className: VolatileTest
 * @Description:
 * @Author: wangyifei
 * @Date: 2022/6/28 8:33
 */
public class VolatileTest {
    public static int sum = 0 ;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    VolatileTest.sum++;
                }

            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {

                for (int i = 0; i < 10000; i++) {
                    VolatileTest.sum++;
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(VolatileTest.sum);
    }
}
